package com.example.app01.model

import android.graphics.Color

class Card(val suit: String, val rank: String,
           var isChosen: Boolean = false,
           var isMatched: Boolean = false) {

    companion object {
        val rankStrings = arrayOf("A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K")
        val validSuits = arrayOf("♥", "♦", "♠", "♣")
    }

    override fun toString(): String {
        return "$suit$rank"
    }

    fun match(otherCards: Array<Card>): Int {
        if (otherCards.size != 1) return 0

        val otherCard = otherCards[0]
        return when {
            otherCard.rank == rank -> 4 // 数字相同
            otherCard.suit == suit -> 1 // 花色相同
            else -> 0
        }
    }

    // 确保花色颜色正确显示
    val suitColor: Int
        get() = when (suit) {
            "♥", "♦" -> Color.RED
            "♠", "♣" -> Color.BLACK
            else -> Color.BLACK
        }
}